//
//  LoveCarChartCell.m
//  New_Runway
//
//  Created by mack on 2018/2/11.
//  Copyright © 2018年 NelsonJ. All rights reserved.
//

#import "LoveCarChartCell.h"

@interface LoveCarChartCell ()
@property (nonatomic, strong)  PYEchartsView *kEchartView;
@property (nonatomic, strong) NSMutableArray *dataArray;

@end

@implementation LoveCarChartCell
-(NSMutableArray *)dataArray{
    
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc] init];
        
    }
    return _dataArray;
}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addAllViews];
        [self creatTitle];
        self.contentView.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

-(void)addAllViews{
    
    _kEchartView = [[PYEchartsView alloc] init];
    [self addSubview:_kEchartView];
    kSelfWeak;
    [_kEchartView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf).mas_offset(-5);
        make.left.right.equalTo(weakSelf);
        make.bottom.equalTo(weakSelf).mas_offset(-30);
    }];
    [self initRagarView];
    

}
-(void)creatTitle{
    kSelfWeak;
    UILabel *titleL = [[UILabel alloc] init];
    [self addSubview:titleL];
    titleL.textColor = MAIN_FONT_COLOR();
    titleL.textAlignment = NSTextAlignmentLeft;
    titleL.text = @"注： 橘色面积越大性价比越高，越值得购买";
    titleL.font = [UIFont systemFontOfSize:12];
    [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf);
        make.left.equalTo(weakSelf).mas_offset(20);
        make.bottom.equalTo(weakSelf).mas_offset(-15);
    }];
    
}
-(void)initRagarView{
//        NSString *json = @"{\"title\":{\"text\":\"\",\"subtext\":\"\"},\"tooltip\":{\"\":\"\"},\"legend\":{\"x\":\"center\",\"data\":[\"\",\"\"]},\"toolbox\":{\"show\":false,\"feature\":{\"mark\":{\"show\":false},\"dataView\":{\"show\":false,\"readOnly\":false}}}}";
    NSString *json = @"";
        NSData *jsonData = [json dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:nil];
        PYOption *option = [RMMapper objectWithClass:[PYOption class] fromDictionary:jsonDic];
    option.animation = YES;
    PYPolar *polar = [[PYPolar alloc] init];
    polar.type = PYPolarTypePolygon;
    polar.radius = @"50%";
    NSArray *array1 =  @[
                         @{
                             @"text":@"排量",
                             @"max":@10
                             
                             },
  
                        @{
                            @"text":@"车龄",
                            @"max":@15

                            },
                        @{
                            @"text":@"里程",
                            @"max":@20

                            },
                       
                         @{
                             @"text":@"价格",
                             @"max":@80

                             },
                         @{
                             @"text":@"过户次数",
                             @"max":@10
                             
                             }];
    polar.radius = @100;
    NSMutableArray *polars =[[NSMutableArray alloc]init];
    [polars addObjectsFromArray:array1];
    polar.indicator = polars;

    NSMutableArray *ploarArray = [[NSMutableArray alloc] init];
    [ploarArray addObject:polar];
    [option setPolar:ploarArray];

    PYSeries *series = [[PYSeries alloc] init];
    series.type = PYSeriesTypeRadar;
    series.name = @"偏爱车辆";
    series.tooltip = [[PYTooltip alloc] init];
    series.clickable = YES;
    series.itemStyle = [[PYItemStyle alloc] init];
    series.itemStyle = [[PYItemStyle alloc] init];
    series.itemStyle.normal = [[PYItemStyleProp alloc] init];
    series.itemStyle.normal.lineStyle = [[PYLineStyle alloc] init];
    series.itemStyle.normal.areaStyle = [[PYAreaStyle alloc] init];
    series.itemStyle.normal.areaStyle.type = PYAreaStyleTypeDefault ;
    series.itemStyle.normal.lineStyle.shadowColor = PYRGBA(0, 0, 0, .4);
    NSMutableArray *valueArr = [[NSMutableArray alloc] init];
    NSDictionary *dic =
                    @{
                        @"name":@"偏爱系数",
                        @"value":self.dataArray
                        };
    
    [valueArr addObject:dic];
    series.data = valueArr;
    NSMutableArray *dataArray = [[NSMutableArray alloc] init];
    [dataArray addObject:series];
    [option setSeries:dataArray];
    
    [_kEchartView setOption:option];

    
}

-(void)setInfoModel:(CustomerInfoModel *)infoModel{
    
    _infoModel = infoModel;
    Carradarlist *model = infoModel.result.intentionInfo.carRadarList;
    [self.dataArray removeAllObjects];
    if (model.carDisplacement > 10) {
        [self.dataArray addObject:@(10)];

    }else if (model.carDisplacement <= 0){
        [self.dataArray addObject:@(0)];

    }else{
        [self.dataArray addObject:@(model.carDisplacement)];

    }
    
    if (model.carAge > 15) {
        [self.dataArray addObject:@(0)];

    }else{
        [self.dataArray addObject:@(15 - model.carAge)];

    }
    if (model.carMileage > 20) {
        [self.dataArray addObject:@(0)];

    }else{
        [self.dataArray addObject:@(20 - model.carMileage)];

    }

    if (model.carRetailPrice > 80) {
        [_dataArray addObject:@(0)];
    }else if(80 > model.carRetailPrice > 0){
        
        [_dataArray addObject: @(80 - model.carRetailPrice)];
    }else{
        [_dataArray addObject:@(80)];
    }
    if (model.carTransferNum > 10) {
        [self.dataArray addObject:@(0)];

    }else{
        [self.dataArray addObject:@(10 - model.carTransferNum)];

    }    
    
    [_kEchartView loadEcharts];


    
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
